<?php

class Authentification extends CI_Controller
{
	
	public function authentifier($etat)
	{
		$this->load->helper('url');
		
		if($etat == "accueil")
		{
			// Chargement du helper form et affichage des vues souhaitees
			$this->load->helper('form');
			$this->load->view('header.php');
			$this->load->view('v_authentification.php');
			$this->load->view('footer.php');
		}
		else
		{
			if($etat == "controle")
			{
				$this->load->model('modeleAuthentificationAdmin');
				$this->load->model('modeleAuthentification');
				$nb = $this->modeleAuthentification->controleAuthentification();
				if ($nb == 0)
				{
					$nbAdmin = $this->modeleAuthentificationAdmin->controleAuthentificationAdmin();

					//Si client n'existe pas on verifie si il n'est pas Admin || Affichage des vues headerAdmin,  accueilAdmin et footerAdmin
					if ($nbAdmin == 0)
					{
						// Chargement du helper form et affichage des vues souhaitees
					$this->load->helper('form');
					$this->load->view('header.php');
					// Affichage de la vue v_authentification (avec passage d'un message ?)
					$this->load->view('v_authentification.php');
					$this->load->view('footer.php');
					$newdata = array
						(
                   			'matricule'  => '',
               			);
               			$this->session->set_userdata($newdata);

					
					}else
					{
						$newdata = array
						(
                   			'admin'  => '1',
               			);
               			$this->session->set_userdata($newdata);
						$this->load->view('headerAdmin.php');
						$this->load->model('modeleSessionAdmin');
						$data['enregt'] = $this->modeleSessionAdmin->listeValidationAdmin();
						$this->load->view('v_accueilAdmin',$data);
					}

			redirect('/accueil/index','refresh');
					
				}
				else
				{
					$newdata = array
						(
                   			'admin'  => '2',
               			);
               		$this->session->set_userdata($newdata);
					$this->load->view('headerClient.php');
					$this->load->view('v_accueil.php');
					$this->load->view('footer.php');
					
				}
				redirect('/accueil/index','refresh');
			}
		} 
	}
	public function deco()
	{
		$this->load->helper('url');
		$this->session->sess_destroy();
		redirect('/accueil/index','refresh');
	}
}
/* End of file Authentification.php */
/* Location: ./application/controllers/authentification.php */
?>